package com.cxs.controller;

import com.cxs.model.R;
import com.cxs.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * @Author: cxs
 * 文件管理
 */
@RestController
@RequestMapping("file")
public class FileController {


    @Autowired
    private FileService fileService;

    @PostMapping("upload")
    public R<String> uploadFile(MultipartFile file, String bucketName, String uniqueIdentifier) {
        String s = fileService.uploadFile(bucketName, file, uniqueIdentifier);
        return R.success(s);
    }


    @GetMapping("download")
    public void download(String bucketName, String filePath, HttpServletResponse response) {
        fileService.downloadFile(bucketName, filePath, response);
    }
}
